//
//  SXTMyMessageTableView.m
//  8.18项目
//
//  Created by ma c on 16/8/18.
//  Copyright © 2016年 zhang. All rights reserved.
//

#import "SXTMyMessageTableView.h"
#import "SXTMyMessageTableViewCell.h"//列表中cell
#import "SXTMyMessageHeadView.h"

@interface SXTMyMessageTableView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray * messageTableSource;

@end


@implementation SXTMyMessageTableView

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
//        self.bounces = NO;
        self.backgroundColor = MainColor;
    }
    return self;

}


-(NSArray *)messageTableSource {

    if (!_messageTableSource) {
        _messageTableSource = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SXTMyMessageTablePlist" ofType:@"plist"]];
    }
    return _messageTableSource;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    NSDictionary * loginDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ISLOGIN"];
    if (loginDic.count) {
        return 6;
    }else{
        return 4;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SXTMyMessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[SXTMyMessageTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
        
    }
    cell.sourceDic = self.messageTableSource[indexPath.row];

    if (indexPath.row == 3) {
        UIImageView * nextImage = [cell valueForKey:@"nextImage"];
        nextImage.hidden = YES;
        
        UILabel * phoneNum = [[UILabel alloc]init];
        phoneNum.textColor = RGB(123, 124, 128);
        phoneNum.text = @"400-100-1111";
        [cell addSubview:phoneNum];
        
        __weak typeof(cell) weakSelf = cell;
        [phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mas_right).offset(-15);
            make.centerY.equalTo(weakSelf.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(110, 15));
            
        }];
    }
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    NSDictionary *loginDic = [[NSUserDefaults standardUserDefaults]valueForKey:@"ISLOGIN"];
    if (loginDic.count) {
        UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 100)];
        footView.backgroundColor = MainColor;
        UIButton * exitBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        exitBtn.frame = CGRectMake(50, 42, VIEW_WIDTH - 100, 45);
        [exitBtn addTarget:self action:@selector(exitBtnMethod) forControlEvents:(UIControlEventTouchUpInside)];
        [exitBtn setImage:[UIImage imageNamed:@"我的界面退出登录按钮"] forState:(UIControlStateNormal)];
        [footView addSubview:exitBtn];
        return footView;
    }
    return nil;
}

- (void)exitBtnMethod{

    if (_exitblock) {
        _exitblock();
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"我选中的是第%li",indexPath.row);
}


@end
